package ed.hbut.supermarket1.mapper;

import ed.hbut.supermarket1.entity.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {


    @Select("select * from category ")
    List<Category> getAllCategory();

    @Insert("insert into category(CategoryName,CategoryQuantity) value (#{categoryName},#{categoryQuantity})")
    void add(Category category);

    @Update("update category set CategoryName=#{categoryName} where CategoryID=#{categoryId}")
    void updateCategory(Category category);


    Integer getCategoryQuantities(Integer categoryId);

    @Select("select COUNT(*) from merchandise where MerchandiseCategoryID=#{categoryId}")
    Integer setCategoryQuantities(int categoryId);

    @Update("update category set CategoryQuantity=CategoryQuantity+1 where CategoryID=#{merchandiseCategoryId}")
    void CategoryAddOne(Integer merchandiseCategoryId);

    @Delete("delete from category where CategoryID=#{id}")
    void delete(int id);

    @Update("update category set CategoryQuantity=CategoryQuantity-1 where CategoryID=#{categoryid}")
    void deleteMerchandiseSubtractOne(Integer categoryid);
}
